#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>

int main() {
   int fd = open("test.txt", O_RDONLY);
   int con=10;
   int con1=5;
    if (fd == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    pid_t pid = fork();
    if (pid == -1) {
        perror("fork");
        close(fd);
        exit(EXIT_FAILURE);
    }

    if (pid == 0) {
        while(con){
        printf("子进程 PID: %d,con:%d\n", getpid(),con);
        con--;
        sleep(1);
        }
    }
     else {
        while(1) 
        { 
        printf("父进程 PID: %d\n", getpid());
        con1--;
        sleep(1);
    }
     }

    return 0;
}
